function CellSpritesContext(cellSprites, cellColumnsCount, cellRowsCount, debugConsole) {

	this.cellSprites = cellSprites;
	
	this.startPathCell;
	this.endPathCell;
	
	this.cellColumnsCount = cellColumnsCount;
	this.cellRowsCount = cellRowsCount;
	
	this.debugConsole = debugConsole;
	
	/**
	 * @public
	 */
	this.getCellSprites = function() {
		return this.cellSprites;
	};
	
	/**
	 * @public
	 */
	this.clear = function() {
		this.startPathCell = null;
		this.endPathCell = null;
		$.each(this.cellSprites, function(index) {
			this.makePassableCell();
			this.unmakePathCell();
			this.unmakeStartPathCell();
			this.unmakeEndPathCell();
			this.unmakeExploredNodeCell();
		});
	};
	
	/**
	 * @public
	 */
	this.displayPath = function() {
		if(this.startPathCell != null && this.endPathCell != null) {
			this.clearInnerPathCells();
			this.clearExploredNodeCells();
			somewhatPassablePoints = new Array();
			impassablePoints = new Array();
			var self = this;
			
			$.each(self.cellSprites,function(index) {
				var cellSprite = this;
				if(cellSprite.getCurrentColor() == CellSpriteColor.IMPASSABLE) {
					impassablePoints.push([cellSprite.getCellX(), cellSprite.getCellY()]);
				} else if(cellSprite.getCurrentColor() == CellSpriteColor.SOMEWHAT_PASSABLE) {
					somewhatPassablePoints.push([cellSprite.getCellX(), cellSprite.getCellY()]);
				}  
			});
			
			area = new Area(this.cellColumnsCount, this.cellRowsCount, somewhatPassablePoints, impassablePoints);
			dc = new DistanceCalculator();
			aStar = new AStar();
			
			path = aStar.getPath(this.startPathCell.getCellX(), this.startPathCell.getCellY(), this.endPathCell.getCellX(), this.endPathCell.getCellY(), area, dc, 3);
			
			this.debugConsole.clearConsole();
			if(!path.reachesDestination) {
				this.debugConsole.toConsole("Unreachable, tracing back from (heuristically) closest, reachable node (phew!).");
			}
			this.debugConsole.toConsole("Explored "+path.exploredNodes.length+" nodes.");
			this.debugConsole.toConsole("Path has "+path.nodes.length+" nodes.");
			this.debugConsole.toConsole("Took "+path.computeTimeMs+" ms.");			
			
			$.each(path.exploredNodes,function(index) {
			    var node = this;		
			    $.each(self.cellSprites,function(index) {
			    	var cellSprite = this;
			    	if(cellSprite.getCellX() == node.x && 
			    			cellSprite.getCellY() == node.y) {
			    		cellSprite.makeExploredNodeCell();
			    	}
			    });
			});
			
			$.each(path.nodes,function(index) {
			    var node = this;
			    $.each(self.cellSprites,function(index) {
			    	var cellSprite = this;
			    	if(cellSprite.getCellX() == node.x && 
			    			cellSprite.getCellY() == node.y) {
			    		cellSprite.makeInnerPathCell();
			    	}
			    });
			});
		}
	};
	
	this.clearStartPathCell = function()  {
		this.clearInnerPathCells();
		if(this.startPathCell != null) {
			this.startPathCell.unmakeStartPathCell();
		}
	};
	
	this.clearEndPathCell = function()  {
		this.clearInnerPathCells();
		this.clearExploredNodeCells();
		if(this.endPathCell != null) {
			this.endPathCell.unmakeEndPathCell();
		}
	};
	
	this.clearInnerPathCells = function() {
		var self = this;
		
		$.each(self.cellSprites,function(index) {
			var cellSprite = this;
			if(cellSprite.isPath) {
				cellSprite.unmakePathCell();
			}
		});
	};
	
	this.clearExploredNodeCells = function() {
		var self = this;
		
		$.each(self.cellSprites,function(index) {
			var cellSprite = this;
			if(cellSprite.isExploredNode) {
				cellSprite.unmakeExploredNodeCell();
			}
		});
	};
	
	this.setStartPathCell = function(cell) {
		this.startPathCell = cell;
		this.displayPath();
	};
	
	this.setEndPathCell = function(cell) {
		this.endPathCell = cell;
		this.displayPath();
	};
	
	this.getImpassableCells = function() {
		iCells = new Array();
		var self = this;
		$.each(self.cellSprites,function(cell) {
		    if(this.getCurrentColor() == CellSpriteColor.IMPASSABLE) {
		    	iCells.push(this);
		    }
		});
		return iCells;
	};
	
	this.getSomewhatPassableCells = function() {
		spCells = new Array();
		var self = this;
		$.each(self.cellSprites,function(index) {
		    if(this.getCurrentColor() == CellSpriteColor.SOMEWHAT_PASSABLE) {
		    	spCells.push(this);
		    }
		});
		return spCells;
	};
	
}